package com.nulldev.util.osAPI.hardware.gpu;

import com.nulldev.util.VariableAPI.ArrayUtils;
import com.nulldev.util.VariableAPI.MathUtil;
import com.nulldev.util.VariableAPI.StringsUtil;

public class D3DUtil {
	/*
	 * TODO: Move to an enum -> D3DLevel TODO: Add Ultimate support TODO: Add a more
	 * complete list.
	 */

	@SuppressWarnings("unused")
	private static final Brand[] D3D_12_ULTIMATE =
		{ Brand.RADEON_RX, Brand.RADEON_RX_VEGA, Brand.GEFORCE_GTX, Brand.TESLA };
	private static final Brand[] D3D_12 =
		{ Brand.AMD_HD_7XXX, Brand.RADEON_RX, Brand.RADEON_RX_VEGA, Brand.AMD_R3, Brand.AMD_R5, Brand.AMD_R7, Brand.AMD_R9, Brand.GEFORCE_GTX, Brand.TESLA };
	private static final Brand[] D3D_11 =
		{ Brand.AMD_HD_7XXX, Brand.AMD_HD_6XXX, Brand.AMD_HD_5XXX, Brand.AMD_HD_4XXX, Brand.RADEON_RX, Brand.RADEON_RX_VEGA, Brand.AMD_R3, Brand.AMD_R5,
				Brand.AMD_R7, Brand.AMD_R9, Brand.GEFORCE_GTX, Brand.INTEL_HD_4XX, Brand.INTEL_HD_5XX, Brand.INTEL_HD_6XX, Brand.TESLA, Brand.AMD_HD_8XXX };
	private static final Brand[] D3D_10 =
		{ Brand.AMD_HD_8XXX, Brand.AMD_HD_7XXX, Brand.AMD_HD_6XXX, Brand.AMD_HD_5XXX, Brand.AMD_HD_4XXX, Brand.AMD_HD_3XXX, Brand.AMD_HD_2XXX, Brand.RADEON_RX,
				Brand.RADEON_RX_VEGA, Brand.AMD_R3, Brand.AMD_R5, Brand.AMD_R7, Brand.AMD_R9, Brand.GEFORCE_GTX, Brand.GEFORCE, Brand.INTEL_HD_4XX,
				Brand.INTEL_HD_5XX, Brand.INTEL_HD_6XX, Brand.TESLA };
	private static final Brand[] D3D_9 =
		{ Brand.AMD_HD_8XXX, Brand.AMD_HD_7XXX, Brand.AMD_HD_6XXX, Brand.AMD_HD_5XXX, Brand.AMD_HD_4XXX, Brand.AMD_HD_3XXX, Brand.AMD_HD_2XXX,
				Brand.AMD_HD_1XXX, Brand.RADEON_RX, Brand.RADEON_RX_VEGA, Brand.AMD_R3, Brand.AMD_R5, Brand.AMD_R7, Brand.AMD_R9, Brand.GEFORCE_GTX,
				Brand.GEFORCE, Brand.INTEL_HD_4XX, Brand.INTEL_HD_5XX, Brand.INTEL_HD_6XX, Brand.TESLA };
	private static final Brand[] D3D_8 = D3D_9;
	private static final Brand[] D3D_7 = ArrayUtils.addAll(D3D_8, new Brand[]
		{ Brand.GEFORCE_OLD, Brand.AMD_XT });
	private static final Brand[] D3D_6 = D3D_7;
	private static final Brand[] D3D_5 = D3D_6;
	private static final Brand[] D3D_4 = D3D_5;
	private static final Brand[] D3D_3 = D3D_4;
	private static final Brand[] D3D_2 = D3D_3;
	private static final Brand[] D3D_1 = D3D_2;

	public static boolean isD3DReady(final GPU gpu, final int level) {
		final int dx = (int) MathUtil.clamp(1, 12, level);

		if (dx == 12) {
			if (gpu.getVendor() == Vendor.NVIDIA && gpu.getBrand() == Brand.GEFORCE_GTX) {
				if (StringsUtil.isEqual(gpu.getData(), 3, "770")) {
					return false;
				} else {
					return ArrayUtils.contains(D3D_12, gpu.getBrand());
				}
			} else {
				return ArrayUtils.contains(D3D_12, gpu.getBrand());
			}
		} else if (dx == 11) {
			return ArrayUtils.contains(D3D_11, gpu.getBrand());
		} else if (dx == 10) {
			return ArrayUtils.contains(D3D_10, gpu.getBrand());
		} else if (dx == 9) {
			return ArrayUtils.contains(D3D_9, gpu.getBrand());
		} else if (dx == 8) {
			return ArrayUtils.contains(D3D_8, gpu.getBrand());
		} else if (dx == 7) {
			return ArrayUtils.contains(D3D_7, gpu.getBrand());
		} else if (dx == 6) {
			return ArrayUtils.contains(D3D_6, gpu.getBrand());
		} else if (dx == 5) {
			return ArrayUtils.contains(D3D_5, gpu.getBrand());
		} else if (dx == 4) {
			return ArrayUtils.contains(D3D_4, gpu.getBrand());
		} else if (dx == 3) {
			return ArrayUtils.contains(D3D_3, gpu.getBrand());
		} else if (dx == 2) {
			return ArrayUtils.contains(D3D_2, gpu.getBrand());
		} else if (dx == 1) {
			return ArrayUtils.contains(D3D_1, gpu.getBrand());
		}
		return false;
	}
}
